#ifndef _EXLOBBY_AUTO_CASE_H__
#define _EXLOBBY_AUTO_CASE_H__

#include <AtlasBase.h>
#include <AtlasCommon.h>
#include <AtlasClient.h>
#include <AtlasServer.h>

#include <StressCase.h>

#include "ExLobbyDDL.h"
#include "ExLobbyCommon.h"


namespace Atlas
{
	class CExLobbyAutoCase : public Atlas::CStressCase
	{
		enum CASE_STATE
		{
			CS_LOGIN_NA = Atlas::CClient::CLIENT_NA,
			CS_LOGINED = Atlas::CClient::CLIENT_LOGINED,
			CS_CREATE_AVATAR,
			CS_SEL_AVATAR,
			CS_LIST_ROOM,
			CS_CARETE_ROOM,
			CS_ENTER_ROOM,
			CS_SENDMSG,
			CS_LEAVE_ROOM,

			CS_WAIT4SER,

			CS_MAX,
		};
		typedef DDLStub::LOBBY_S2C<CClient, CExLobbyAutoCase>						LOBBY_S2C_STUB;
		typedef CNodeStub<LOBBY_S2C_STUB, CClient, CExLobbyAutoCase>				LOBBY_STUB;
	public:
		CExLobbyAutoCase();
		virtual ~CExLobbyAutoCase();
	
		virtual void OnAttach();
		virtual void OnTick();
		virtual void OnDetach();
		virtual void OnData(_U16 id, _U32 len, const _U8* data);

		void OnConnectFailed();
		void OnConnect();
		void OnLoginDone();

		CStressCase* CExLobbyAutoCase::Create();

		//for test case
		void Echo(CClient* pClient, std::string strEcho);
		void LoginDone(CClient* pClient);
		void AvatarList(CClient* pClient, EXLOBBY_AVATAR *list, _U32 count);
		void NoAvatar(CClient* pClient);
		void CreateAvatarResult(CClient* pClient, _U32 errcode);
		void AvatarSelected(CClient* pClient, _U32 aid);

		void ListRoomResult(CClient* pClient, ROOM_INFO *lists, _U32 count);
		void CreateRoomResult(CClient* pClient, _U64 id);
		void ReceiveMessage(CClient* pClient, std::string msg);
		void EnterRoomResult(CClient* pClient, _U32 errcode);
		void LeaveRoomResult(CClient* pClient, _U32 errcode);

	protected:
		void ClearState();
		void OnStateTick();

		virtual void _GetInfo(std::string& info);

	protected:
		_U32 m_nSuccTimes; 
		_U32 m_nFailedTimes;	

		CASE_STATE m_eCaseState;

		_U32 m_aid;	//cur avatarid and only one avatar
		_U64 m_rid;	//cur roomid and index based from 0

		int m_nAvatarListCount;
		_U64 m_RoomList[MAX_ROOM_LIST_LEN];
		int m_nRoomCount;
		int m_nRoomIndex;

		_U32 m_nSendMsgTimes;
		LOBBY_STUB m_LobbyStub;
	};
}
#endif //_EXLOBBY_AUTO_CASE_H__